﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.WebApiTool
{
    public class DAction
    {
        public string Name { get; set; }
        public Type Type { get; set; }

        public string HttpMethod { get; set; }
        public bool IsAnonymous { get; set; }

        public string Description { get; set; }

        public List<DParameter> Parameters { get; set; }
        public List<DResult> Results { get; set; }

        public DAction(Type type, string name, string httpMethod, bool isAnonymous, string description)
        {
            this.Type = type;
            this.Name = name;
            this.HttpMethod = httpMethod;
            this.IsAnonymous = isAnonymous;
            this.Description = description;

            Parameters = new List<DParameter>();
            Results = new List<DResult>();
        }

        public void AddParameter(DParameter parameter)
        {
            Parameters.Add(parameter);
        }

        public DResult AddResult(DResult result)
        {
            Results.Add(result);
            return result;
        }

        public DResult GetResult(Type type)
        {
            foreach (var result in Results)
            {
                if(result.Type == type)
                {
                    return result;
                }
            }
            return null;
        }
    }
}
